class BaseTreeChoice {
    constructor(getTreeUrl) {
        this.getTreeUrl = getTreeUrl;
        this.first = 0;
    }
    InitTreeObject() {
        // 初始化树形控件
        $('#treeContent').jstree({
            "core": {
                "animation": 200,
                "multiple": false,
                "check_callback": true,
                "themes": {
                    "responsive": true,
                    "dots": false,
                    "icons": true
                },
                "data": {
                    'dataType': 'JSON',
                    'contentType': 'application/json; charset=utf-8',
                    'type': 'GET',
                    'url': parent.basePath + this.getTreeUrl,
                    'data': (node) => {
                        let _nodeId = node.id === '#' ? -1 : (node.id === 'j1_1' ? 0 : node.id);
                        return {'parentKey': _nodeId, 'isPopupWnd': 0, 'isAdministrator': 1};
                    },
                    'complete': () => {
                    }
                }
            },
            "types": {
                "#": {"max_depth": -1, "max_children": -1, "valid_children": ["root"]},
                "root": {"max_depth": -1, "max_children": -1, "icon": parent.basePath + "/images/tree/root.png", "valid_children": -1},
                "default": {"max_depth": -1, "max_children": -1, "valid_children": -1},
                "leaf": {"max_depth": -1, "max_children": -1, "icon": parent.basePath + "/images/tree/folder_close.png", "valid_children": -1},
                "trash": {"max_depth": -1, "max_children": -1, "icon": parent.basePath + "/images/tree/trash.png", "valid_children": -1}
            },
            "plugins": ["types", "wholerow"]
        });
        $('#treeContent').on('select_node.jstree', (event, data) => {
            var _selectedNodeId = data.node.id;
            var _select_node = $("#" + _selectedNodeId);
            _selectedNodeId = _selectedNodeId === "j1_1" ? 0 : _selectedNodeId;
            // 设置选择结果
            var item = new Array(_selectedNodeId, _select_node.attr("fullName"));
            window.parent.arrChoice.push(item);
            window.parent.choice_success = true;
            closePopupWnd();
        });

        // 节点展开后，重新设置图标
        $('#treeContent').on('open_node.jstree', (event, data) => {
            let ref = $.jstree.reference('treeContent');
            let _nodeIdOfSelected = data.node.id;
            let _nodeOfSelected = $("#" + _nodeIdOfSelected);
            if (_nodeIdOfSelected !== "j1_1") {
                if (ref.get_type(_nodeOfSelected) !== "trash") {
                    ref.set_icon(_nodeOfSelected, parent.basePath + "/images/tree/folder_open.png");
                } else {
                    ref.set_icon(_nodeOfSelected, parent.basePath + "/images/tree/trash_o.png");
                }
            }
        });
        // 节点收回后，重新设置图标
        $('#treeContent').on('close_node.jstree', (event, data) => {
            let ref = $.jstree.reference('treeContent');
            let _nodeIdOfSelected = data.node.id;
            let _nodeOfSelected = $("#" + _nodeIdOfSelected);
            if (_nodeIdOfSelected !== "j1_1") {
                if (ref.get_type(_nodeOfSelected) !== "trash") {
                    ref.set_icon(_nodeOfSelected, parent.basePath + "/images/tree/folder_close.png");
                } else {
                    ref.set_icon(_nodeOfSelected, parent.basePath + "/images/tree/trash.png");
                }
            }
        });
        // 所有节点完成装载，只运行一次
        $('#treeContent').on('ready.jstree', () => {
            let ref = $.jstree.reference('treeContent');
            let _obj = $("#j1_1");
            ref.open_node(_obj);     // 打开当前第一层节点
            $("#loading").hide();
        });

    }
}